Skip to content

feat: Add CacheTagService to @cacheable/utils#1646

Open
cupofjoakim wants to merge 6 commits into
jaredwray:mainfrom
cupofjoakim:main
Open

feat: Add CacheTagService to @cacheable/utils#1646
cupofjoakim wants to merge 6 commits into
jaredwray:mainfrom
cupofjoakim:main

Conversation

@cupofjoakim
Copy link
Copy Markdown

Please check if the PR fulfills these requirements

  • Followed the Contributing guidelines and Code of Conduct
  • Tests for the changes have been added (for bug fixes/features) with 100% code coverage.

What kind of change does this PR introduce?
As suggested in #1640, this PR implements CacheTagService in the @cacheable/utils package. It is a standalone service that adds tag-based invalidation on top of any Keyv store, without touching adapters or the cacheable core.

The invalidation model is lazy, in the spirit of Symfony's tag-aware cache and Next.js's revalidateTag: invalidateTag it bumps a per-tag version counter rather than scanning and deleting keys. isKeyFresh compares each key's stored tag snapshot to current versions. That keeps invalidation constant-time at the cost of one extra read per cache lookup.

Integration into cacheable and cache-manager are intentionally left for follow-ups so this PR stays focused on the primitive. Optimisations per-store type (like an atomic Redis fast path using Lua) are also natural follow ups.

@cupofjoakim cupofjoakim marked this pull request as ready for review May 27, 2026 09:38
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the CacheTagService utility, which provides tag-based cache invalidation on top of any Keyv store using a lazy invalidation model. The feedback highlights opportunities to parallelize sequential asynchronous operations using Promise.all in setKeyTags, isKeyFresh, and invalidateTags to prevent performance bottlenecks when handling multiple tags.

Comment thread packages/utils/src/cache-tag-service.ts Outdated
Comment thread packages/utils/src/cache-tag-service.ts Outdated
Comment thread packages/utils/src/cache-tag-service.ts Outdated
@cupofjoakim
Copy link
Copy Markdown
Author

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the CacheTagService to provide tag-based invalidation on top of any Keyv store using a lazy invalidation model. The feedback suggests defensive checks in getTagVersions to ensure compatibility with older or custom Keyv stores that might not return an array. Additionally, it recommends deduplicating the input tags in both setKeyTags and invalidateTags to prevent redundant store queries and duplicate writes.

Comment thread packages/utils/src/cache-tag-service.ts Outdated
Comment thread packages/utils/src/cache-tag-service.ts Outdated
Comment thread packages/utils/src/cache-tag-service.ts Outdated
@jaredwray jaredwray changed the title Add CacheTagService to @cacheable/utils feat: Add CacheTagService to @cacheable/utils Jun 6, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (7d58420) to head (9bd1ec3).

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #1646   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           26        27    +1     
  Lines         2747      2820   +73     
  Branches       613       622    +9     
=========================================
+ Hits          2747      2820   +73     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants